Page({
  data: {
    current: -1
  },
  onLoad: function () {
    wx.util.request('common.helper.list').then(res => {
      this.setData({
        list: res
      });
    });
  },
  change: function (e) {
    let idx = e.detail.index,
        item = this.data.list[idx];
    if (item.child.length) {
      this.setData({
        current: this.data.current == idx ? -1 : idx
      });
    } else {
      this.setData({
        current: -1
      });
      this.detail(item.id);
    }
  },
  detail: function (e) {
    let id = isNaN(e) ? e.currentTarget.dataset.id : e;
    wx.navigateTo({
      url: `detail?id=${id}`
    })
  }
})